import axios from "axios"
import { ElMessage } from "element-plus"
//1. 创建axios对象
const service = axios.create({
  // baseURL: "/api",
  baseURL: window.streamingConfig.Baseurl,
  timeout: 50000
})
//2. 请求拦截器
service.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    Promise.reject(error)
  }
)

//3. 响应拦截器
service.interceptors.response.use(
  (response) => {
    //判断code码
    return response.data
  },
  (error) => {
    if (error.response && error.response.data) {
      const code = error.response.status
      const msg = error.response.data.message
      ElMessage.error(`Code: ${code}, Message: ${msg}`)
      // console.error(`[Axios Error]`, error.response);
    } else {
      ElMessage.error(`${error}`)
    }
    return Promise.reject(error)
  }
)
export default service
